<%--
  Created by IntelliJ IDEA.
  User: ZhuChunXiao
  Date: 2017/5/25
  Time: 15:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<div id="page-content">
  <div class="row">

    <div class="col-lg-12">
      <div class="panel">
        <div class="panel-heading">
          <h3 class="panel-title">流程简要</h3>
        </div>
        <div class="panel-body">
          <div class="form-inline">
            <div class="row">
              <div class="col-sm-12 table-toolbar-left">
                <btn id="ajax_process_btn_add" class="btn btn-primary btn-sm">
                  <i class="ti-plus"> </i> 新建流程简要表
                </btn>
              </div>
            </div>
          </div>
          <div class="table-jqgrid">
            <table id="ajax_process_table" >
            </table>
            <div id="ajax_process_list_page">
            </div>
          </div>
        </div>
      </div>
    </div>

  </div>
</div>



<script type="text/javascript">

  $("#ajax_process_btn_add").click(function(){
    loadURL("<%=path%>/main/processBrief/input", $('#page-content'));
  });


  $(function(){
    jQuery("#ajax_process_table").jqGrid({
      url:'<%=path%>/main/processBrief/list',
      datatype: "json",
      colNames:["创建日期",'流程名称',"关联的表单名称","操作","id"],
      colModel:[
        {name:'createDate',index:'createDate', width:100,sortable:true,search:true,searchoptions:{sopt:['cn']}},
        {name:'name',index:'name', width:150,sortable:true,search:true,searchoptions:{sopt:['cn']}},
        {name:'tableName',index:'tableName', width:150,sortable:true,search:true,searchoptions:{sopt:['cn']}},
        {name:'act',index:'act', width:150,sortable:false,search:false,fixed:true},
        {name:'id',index:'id', width:50,key:true,hidden:true}
      ],
      loadonce: true,
      rowNum : 10,
      rowList:[10,20,30],
      pager : '#ajax_process_list_page',
      sortname : 'createTime',
      sortorder : "desc",
      gridComplete:function(){
        var ids=$("#ajax_process_table").jqGrid('getDataIDs');
        for(var i=0;i<ids.length;i++){
          var cl=ids[i];
          var rowData = $("#ajax_process_table").jqGrid("getRowData",cl);
          var de= '<button class="btn btn-default btn-xs" data-original-title="编辑" onclick="fn_process_read(\'' + cl+  '\');"><i class="fa fa-pencil-square-o"> </i> 编辑</button> ';
          var dt= '<button class="btn btn-danger btn-xs" data-original-title="删除" onclick="fn_process_destroy(\'' +cl + '\');"><i class="fa fa-trash-o"> </i> 删除</button>';

          jQuery("#ajax_process_table").jqGrid('setRowData',ids[i],{act:de+dt});
        }


      },
      onSelectRow: function (rowId, status, e) {
        var rowId = $("#ajax_process_table").jqGrid('getGridParam','selrow');
        var rowDatas = $("#ajax_process_table").jqGrid('getRowData', rowId);
      },
      jsonReader: {
        root: "dataRows",
        page: "page",
        total: "total",
        records: "records",
        repeatitems : false
      },
    //  caption : "<i class='fa fa-arrow-circle-right'></i> 流程简要信息",
      multiselect : false,
      rownumbers:true,
      gridview:true,
      shrinkToFit:true,
      viewrecords: true,
      autowidth: true,
      height:'auto',
      forceFit:true,
      loadComplete: function() {
      }
    });
    $(window).on('resize.jqGrid', function() {
     // jQuery("#ajax_process_table").jqGrid('setGridWidth', $("#ajax_process_list_row").width());
    });
    jQuery("#ajax_process_table").jqGrid('filterToolbar',{searchOperators:false,stringResult:true});
    jQuery("#ajax_process_table").jqGrid('navGrid', "#ajax_process_list_page", {
      edit : false,
      add : false,
      del : false,
      search:false
    });

  });

  function fn_process_read(id){
    loadURL("<%=path%>/main/processBrief/input?keyId="+id, $('#page-content'));
  }



  function fn_process_destroy(id) {
    __confirm_dialog(null, '确定要删除吗?',
            function () {
              var url = "<%=path%>/main/processBrief/delete/"+id;
              __ajax_post(url, null, function(pdata) {
                __toastr(pdata);
                jQuery("#ajax_process_table").jqGrid().setGridParam({datatype:'json'}).trigger("reloadGrid");
              });
            });
  }

</script>


